﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace Bird.Core.Infrastructure
{
    public class EngineContext
    {
        [MethodImpl(MethodImplOptions.Synchronized)]
        public static IEngine Initialize(bool forceRecreate)
        {
            if (!Singleton<IEngine>.HasValue || forceRecreate)
            {
                IEngine engine = CreateEngine();
                engine.Initialize();
                Singleton<IEngine>.Instance = engine;
            }
            return Singleton<IEngine>.Instance;
        }
        public static IEngine CreateEngine()
        {
            return new BirdEngine();
        }
        public static IEngine Current
        {
            get
            {
                if (Singleton<IEngine>.Instance == null)
                    Initialize(false);
                return Singleton<IEngine>.Instance;
            }
        }
    }
}
